//
//  ARKitView.m
//  Charles
//
//  Created by Leo on 2019/8/13.
//  Copyright © 2019 charles. All rights reserved.
//

#import "ARKitView.h"

@interface ARKitView ()<ARSCNViewDelegate>

@property (nonatomic, strong) ARSCNView *sceneView; // 显示AR体验
@property (nonatomic, strong) SCNScene *scene;      // 3D场景

@end

@implementation ARKitView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    self.sceneView.frame = self.bounds;
    [self addSubview:self.sceneView];
    self.sceneView.scene = self.scene;
}

#pragma mark - ARSCNViewDelegate

- (BOOL)sessionShouldAttemptRelocalization:(ARSession *)session {
    return YES;
}

- (void)renderer:(id <SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor{
    
}

- (void)renderer:(id <SCNSceneRenderer>)renderer willUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor{

}


- (void)renderer:(id <SCNSceneRenderer>)renderer didUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor{

}

- (void)renderer:(id <SCNSceneRenderer>)renderer didRemoveNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor{

}

- (ARSCNView *)sceneView {
    if (!_sceneView) {
        _sceneView = [[ARSCNView alloc]init];
        _sceneView.delegate = self;
        _sceneView.allowsCameraControl = YES;
    }
    return _sceneView;
}

- (SCNScene *)scene {
    if (!_scene) {
        _scene = [[SCNScene alloc]init];
    }
    return _scene;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
